import Base from "../base.js"
// import GradlesApi from "../../api/gradles.js"
import adminsAdd from "../../api/admins.js"
const adminProst = [

    {
        name: "用户名",
        key: "adminsname"
    },
    {
        name: "密码",
        key: "adminspassword"
    },
   

];
export default class extends Base {
    data = {
        admin: {
            id: "", // mongodb 自动生成的 id   
            adminsname: "21",   
            adminspassword: "12",    
            
        },
    };
    render() {
        // const student=this.data;
        this.$el.html(`
        <h1 style="text-align:center">新增管理员</h1>
       <div>
        <table>
        <tbody>
        ${adminProst.map(item => {
            return `
                <div class="layui-form-item" style="padding: 10px;width:1200px;margin:auto;margin-left:430px">
                <label class="layui-form-label" style="width:190px">${item.name}</label>
                <div class="layui-input-block">
                <input type="text" style="width:190px" placeholder="请输入${item.name}" name="${item.key}" required  lay-verify="required" placeholder="请输入${item.name}" autocomplete="off" class="layui-input" >
                </div>
            </div>
            
            `
        }).join("")}
            <tr>
            </tr>
            <tr>
            <td style="width:650px"></td>
            <td><button class="save-btn layui-btn layui-btn-lg layui-btn">保存</button></td>
            </tr>
            </tbody>
            </table>
        </div>
        `);
    }
    async add() {
        if (confirm("确定要新增吗!")) {
            // $(".upload-btn-poster").attr("disabled", false).removeClass("layui-bg-gray");
            const {_id,username,password } = this.data.admin;
            this.data.admin = await adminsAdd.add({ _id,adminsname,adminspassword  })
        } else {

        }

    }
   
    handle() {
        const { admin } = this.data;
        console.log(admin);
        _.map(admin, (v, k) => {
            // console.log(1);
            if (k === "_id") {
                return;
            }  else {
                $(`input[name=${k}]`).on("input", e => {
                    admin[k] = e.target.value;
                })
            }

        });
        $(".save-btn").on("click", this.add.bind(this));
    }



}